<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑分类 - Echo Network</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
            color: #333;
        }
        .navbar {
            background-color: #2c3e50;
            color: white;
            padding: 15px 0;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .navbar-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .navbar-logo {
            font-size: 1.5rem;
            font-weight: bold;
            color: white;
            text-decoration: none;
        }
        .navbar-menu {
            display: flex;
            list-style: none;
            margin: 0;
            padding: 0;
        }
        .navbar-menu li {
            margin-left: 20px;
        }
        .navbar-menu a {
            color: white;
            text-decoration: none;
            padding: 8px 12px;
            border-radius: 4px;
            transition: background-color 0.2s;
        }
        .navbar-menu a:hover {
            background-color: rgba(255, 255, 255, 0.1);
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 100px 20px 40px;
        }
        h1 {
            font-size: 2rem;
            color: #2c3e50;
            margin-bottom: 30px;
        }
        .card {
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 30px;
            max-width: 800px;
            margin: 0 auto;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #2c3e50;
        }
        input[type="text"], textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            transition: border-color 0.2s;
            box-sizing: border-box;
        }
        input[type="text"]:focus, textarea:focus {
            outline: none;
            border-color: #3498db;
        }
        textarea {
            resize: vertical;
            min-height: 100px;
            font-family: inherit;
        }
        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 500;
            transition: all 0.2s;
            text-decoration: none;
            display: inline-block;
            text-align: center;
        }
        .btn-primary {
            background-color: #3498db;
            color: white;
        }
        .btn-primary:hover {
            background-color: #2980b9;
        }
        .btn-secondary {
            background-color: #95a5a6;
            color: white;
            margin-right: 10px;
        }
        .btn-secondary:hover {
            background-color: #7f8c8d;
        }
        .message {
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 4px;
        }
        .message-success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .message-error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .form-actions {
            margin-top: 30px;
            display: flex;
            gap: 10px;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="navbar-container">
            <a href="/echo-network/admin/category" class="navbar-logo">Echo Network 管理后台</a>
            <ul class="navbar-menu">
                <li><a href="/echo-network/article-list">前台首页</a></li>
                <li><a href="/echo-network/profile-show">个人中心</a></li>
            </ul>
        </div>
    </nav>
    
    <div class="container">
        <h1>编辑分类</h1>
        
        <div class="card">
            <!-- 消息提示 -->
            <div th:if="${message != null}" class="message" th:classappend="${messageType == 'success' ? 'message-success' : 'message-error'}">
                <span th:text="${message}"></span>
            </div>
            
            <!-- 分类表单 -->
            <form id="categoryForm" action="/echo-network/admin/category?action=update" method="post">
                <input type="hidden" name="id" th:value="${category.categoryId}">
                
                <div class="form-group">
                    <label for="categoryName">分类名称 <span style="color: #e74c3c;">*</span></label>
                    <input type="text" id="categoryName" name="categoryName" th:value="${category.categoryName}" placeholder="请输入分类名称" maxlength="50" required>
                </div>
                
                <div class="form-group">
                    <label for="categoryDesc">分类描述</label>
                    <textarea id="categoryDesc" name="categoryDesc" th:text="${category.categoryDesc}" placeholder="请输入分类描述（可选）" maxlength="200"></textarea>
                </div>
                
                <div class="form-actions">
                    <a href="/echo-network/admin/category" class="btn btn-secondary">返回列表</a>
                    <button type="submit" class="btn btn-primary">保存修改</button>
                </div>
            </form>
        </div>
    </div>
    
    <script>
        // 表单提交前的验证
        document.getElementById('categoryForm').addEventListener('submit', function(event) {
            const nameInput = document.getElementById('categoryName');
            const name = nameInput.value.trim();
            
            // 验证分类名称
            if (!name) {
                alert('请输入分类名称');
                nameInput.focus();
                event.preventDefault();
                return;
            }
            
            // 验证名称长度
            if (name.length > 50) {
                alert('分类名称长度不能超过50个字符');
                nameInput.focus();
                event.preventDefault();
                return;
            }
            
            // 验证描述长度
            const description = document.getElementById('categoryDesc').value.trim();
            if (description.length > 200) {
                alert('分类描述长度不能超过200个字符');
                document.getElementById('categoryDesc').focus();
                event.preventDefault();
                return;
            }
        });
    </script>
</body>
</html>